<?php

namespace App\Controller\Admin\Exam;


use App\Controller\Admin\BaseController;
use App\Service\Exam\ExamService;
use Hyperf\Di\Annotation\Inject;
use Yj\Apidog\Annotation\ApiController;
use Yj\Apidog\Annotation\FormData;
use Yj\Apidog\Annotation\PostApi;
use Yj\Apidog\AnnotationCollector;

/**
 * @ApiController(prefix="admin/exam/exam")
 */
class ExamController extends BaseController
{
    /**
     * @Inject()
     * @var ExamService
     */
    protected $examService;

    /**
     * @PostApi(path="lists")
     */
    public function lists()
    {
        $data =  $this->examService->lists();
        _SUCCESS($data);
    }

    /**
     * @PostApi(path="edit")
     * @FormData(key="id",rule="required")
     * @FormData(key="title",rule="required")
     * @FormData(key="desc",rule="required")
     * @FormData(key="time",rule="required")
     */
    public function edit()
    {
        $data = $this->getValidatorData();
        $this->examService->edit($data->get('id'), $data->except('id'));
        _SUCCESS();
    }

    /**
     * @PostApi(path="add")
     * @FormData(key="title",rule="required")
     */
    public function add()
    {
        $data = $this->getValidatorData();
        $this->examService->add($data);
        _SUCCESS();
    }

    /**
     * @PostApi(path="delete")
     * @FormData(key="id",rule="required")
     */
    public function delete()
    {
        $id = $this->getValidatorData('id');
        $this->examService->del($id);
        _SUCCESS();
    }
}